<template>
	<!-- 请假 -->
	<view class="building-add">
		<view class="add-content">
			<view class="add-item">
				<view class="item-left">请假日期<text>*</text></view>
				<view class="item-right" @click="show=true">{{date}}</view>
			</view>
			<view class="add-item">
				<view class="item-left">返回日期<text>*</text></view>
				<view class="item-right" @click="show2=true">{{date2}}</view>
			</view>
			<view class="add-item">
				<view class="item-left">请假原因<text>*</text></view>
				<view class="item-right"><textarea v-model="because" placeholder-style="color:#999;font-size:26rpx" placeholder="请输入请假原因"></textarea></view>
			</view>
		</view>
		<view class="btn">
			<view class="btn-1" @click="handleSubmit">提交</view>
		</view>
		
		<u-toast ref="uToast" />
		<!-- -->
		<u-picker mode="time" v-model="show" :params="params" @confirm="confirm"></u-picker>
		<!-- -->
		<u-picker mode="time" v-model="show2" :params="params" @confirm="confirm2"></u-picker>
	</view>
</template>

<script>
	export default{
		data() {
			return{
				show:false,
				show2:false,
				date:'请选择',
				date2:'请选择',
				params: {
					year: true,
					month: true,
					day: true
				},
				because:''
			}
		},
		mounted() {
			
		},
		onShow() {

		},
		onNavigationBarButtonTap() {
			uni.navigateTo({
				url:'./AskForLeaveRecords/AskForLeaveRecords'
			})
		},
		methods:{
			confirm(e) {
				this.date = e.year + '-' + e.month + '-' + e.day
			},
			confirm2(e) {
				this.date2 = e.year + '-' + e.month + '-' + e.day
			},
			// 提交
			handleSubmit() {
				if(this.date == '请选择') {
					return this.$refs.uToast.show({
						title: '请选择请假日期'
					})
				}
				if(this.date2 == '请选择') {
					return this.$refs.uToast.show({
						title: '请选择返回日期'
					})
				}
				if(this.because == '') {
					return this.$refs.uToast.show({
						title: '请填写请假原因'
					})
				}
				let params = {
					data:this.date,
					date2:this.date2,
					content:this.because
				}
				console.log(params)
				this.$u.api.applyLeave(params)
					.then(res => {
						console.log(res)
						if(res.code == 200) {
							this.$refs.uToast.show({
								title: `您已提交${this.date}-${this.date2}请假申请`
							})
							setTimeout(() => {
								uni.navigateBack({
									delta:1
								})
							},1500)
						}
					})
					.catch(err => {
						console.log(err)
					})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.building-add{
		background-color: #f5f6f7;
		min-height: 100vh;
		.add-head{
			display: flex;
			justify-content: space-between;
			align-items: center;
			background-color: #fff;
			height: 180rpx;
			padding: 20rpx;
			.head-left{
				.head-left-1{
					color: #000;
					font-size: 28rpx;
					font-weight: 600;
				}
				.head-left-2{
					color: #999;
					font-size: 24rpx;
					margin-top: 20rpx;
				}
			}
			.head-right{
				background-color: #cecece;
				display: flex;
				justify-content: center;
				align-items: center;
				border-radius: 10rpx;
				width: 150rpx;
				height: 150rpx;
				.img{
					width: 50%;
					height: 50%;
				}
				.img2{
					width: 100%;
					height: 100%;
				}
			}
		}
		.add-content{
			margin-top: 20rpx;
			padding-bottom: 110rpx;
			.add-item{
				display: flex;
				// justify-content: space-between;
				align-items: flex-start;
				padding: 30rpx 20rpx;
				background-color: #fff;
				border-bottom: 1px solid #f4f1f1;
				.item-left{
					color: #333;
					font-size: 28rpx;
					flex: 2;
					text{
						color: #DD524D;
					}
				}
				.item-right{
					font-size: 27rpx;
					color: #999;
					display: flex;
					justify-content: flex-end;
					align-items: center;
					flex: 4;
					input{
						text-align: right;
					}
					input::placeholder{
					    font-size: 26rpx;
					    color: #999;
					}
					textarea{
						
					}
					text{
						display: inline-block;
						margin-left: 5rpx;
					}
				}
			}
		}
		.btn{
			width: 100%;
			height: 110rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			color: #fff;
			font-size: 30rpx;
			background-color: #f4f1f1;
			position: fixed;
			bottom: 0;
			left: 0;
			border-top: 1px solid #CCE6FF;
			.btn-1{
				background-color: #007AFF;
				display: flex;
				justify-content: center;
				align-items: center;
				width: 600rpx;
				height: 80rpx;
				border-radius: 40rpx;
			}
		}
	}
</style>
